/*
 * @(#)AssociationTypeTransformer.java
 * Date 2013-09-08
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.registry.transformer.xds;

import javax.enterprise.context.ApplicationScoped;

import javax.inject.Inject;

import oasis.names.tc.ebxml_regrep.xsd.rim._3.AssociationType1;

import us.hornerscorners.lamppost.exception.ServiceActionException;

import us.hornerscorners.lamppost.model.document.Association;

import us.hornerscorners.lamppost.registry.constant.Metadata;

import us.hornerscorners.lamppost.transformer.AbstractTransformer;


/**
 * Class description
 *
 *
 * @version        v1.0, 2013-09-08
 * @author         Jim Horner
 */
@ApplicationScoped
public class AssociationTypeTransformer
        extends AbstractTransformer<Association, AssociationType1> {

    /** Field description */
    @Inject
    private ClassificationTypeTransformer classificationTransformer;

    /** Field description */
    @Inject
    private SlotTypeTransformer slotTransformer;

    /** Field description */
    @Inject
    private VersionInfoTypeTransformer versionInfoTransformer;

    /**
     * Constructs ...
     *
     */
    public AssociationTypeTransformer() {
        super();
    }

    /**
     * Method description
     *
     *
     * @param association
     *
     * @return
     */
    @Override
    public AssociationType1 transform(Association association)
            throws ServiceActionException {

        AssociationType1 result = new AssociationType1();

        result.setId(association.getEntryURN());
        result.setAssociationType(association.getAssociationType());
        result.setSourceObject(association.getSourceEntryURN());
        result.setTargetObject(association.getTargetEntryURN());

        // versioning
        result.setLid(association.getEntryLogicalURN());
        result.setVersionInfo(
            this.versionInfoTransformer.transform(association.getEntryVersion()));

        result.getSlot().addAll(
            this.slotTransformer.transform(association.getAttributes()));

        if (association.getDocumentation() != null) {

            result.getClassification().add(
                this.classificationTransformer.transformCodedElement(
                    Metadata.AssociationClassificationNode, association,
                    association.getDocumentation()));
        }

        return result;
    }
}
